package org.ihelpuoo.orm.filter;

/**
 * <b>CharFieldFilter class:</b>
 * <hr color=grey size=1>
 * <pre>Default Fieldfilter. Its constructor accept a string like
 * 
 *      [field name1][field name2][field name3]...
 * 
 * Each filed should be nested by "[" and "]".
 * For example, if you write
 * 
 *     FieldFilter filter = new CharFieldFilter("[id][name]");
 *     
 * Then when you get a field named "id", filter.match(f) will return true.
 * </pre>
 * 
 * Note: the string is case sensitive.
 *
 * @author zozoh  created @ 2007
 *
 */
public class CharFieldFilter extends FieldFilter
{
	private StringBuffer	sb;

	public CharFieldFilter(CharSequence cs)
	{
		if (null == cs)
			sb = new StringBuffer();
		else
			sb = new StringBuffer(cs);
	}

	public CharFieldFilter appendField(String fieldName)
	{
		sb.append('[').append(fieldName).append(']');
		return this;
	}

	@Override
	public boolean match(String name)
	{
		return sb.indexOf("[" + name + "]") != -1;
	}
}
